﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Globalization;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using emp.BLL;
using emp.ProcessFlow.SysManage;
using emp.Utility;

public partial class crm_campaign_CampaignVerifyList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            Bind();

        }
    }

    private void Bind()
    {
        int pageNum = 0;
        if (Request.Params["pageNum"] != null && Request.Params["pageNum"].Equals("") == false)
        {
            try
            {
                pageNum = int.Parse(Request.Params["pageNum"]);
            }
            catch { }
        }
        emp.BLL.Campaign campaign = new emp.BLL.Campaign();
        campaignList.PageIndex = pageNum;
        IList clist = campaign.getCampaignList();
        this.campaignList.DataSource = clist;
        this.campaignList.DataBind();
        PageUtil.setPageCount(campaignList, clist);
    }

    protected void PageChanged(object sender, GridViewPageEventArgs e)
    {

        gview(e.NewPageIndex);

    }

    protected void query_Click(object sender, EventArgs e)
    {
        gview(0);
    }
    /// <summary>
    /// 修改活动
    /// </summary>
    protected void lbt_modift_Click(object sender, EventArgs e)
    {
        string sArg = ((ImageButton)sender).CommandArgument.ToString(CultureInfo.InvariantCulture);
        Response.Redirect("CampaignVerify.aspx?eid=" + sArg);
    }

    /// <summary>
    /// 删除活动
    /// </summary>
    protected void lbt_delete_Click(object sender, EventArgs e)
    {
        string sArg = ((ImageButton)sender).CommandArgument.ToString(CultureInfo.InvariantCulture);
        if (string.IsNullOrEmpty(sArg))
        {
            PubFun.Show(this, "参数错误");
        }
        else
        {
            Campaign bll = new Campaign();
            if (!bll.Delete(Convert.ToInt32(sArg)))
            {
                PubFun.Show(this, "删除活动失败，请重试");
            }
            else
            {
                PubFun.Show(this, "删除活动成功");
                Bind();
            }


        }
    }



    private void gview(int page)
    {


        campaignList.PageIndex = PageUtil.getGviewNewPage(campaignList, page);
        this.pageNum.Value = campaignList.PageIndex.ToString();
        emp.BLL.Campaign campaign = new emp.BLL.Campaign();
        IList clist = campaign.selectCampaignList(this.campaign_id.Text, this.campaign_name.Text, this.txtCreateDate_start.Value, this.txtCreateDate_end.Value, this.txtEndDate_start.Value, this.txtEndDate_end.Value);

        this.campaignList.DataSource = clist;
        this.campaignList.DataBind();

        PageUtil.setPageCount(campaignList, clist);

    }

    protected string getEdit(string st, string id)
    {
        return "CampaignModify.aspx?cam_uid=" + id;//st == "0" ? "CampaignModify.aspx?cam_uid=" + id : "#";
    }
    bool tag = false;
    protected string getOper(string type, string st, string id)
    {

        if (type == "Strat")
        {
            if (st == "0") tag = true;
        }
        else if (type == "End")
        {
            if (st == "1") tag = true;
        }
        else if (type == "Del")
        {
            if (st == "0") tag = true;
        }
        return tag ? "CampaignOperation.aspx?actionType=" + type + "&id=" + id : "#";

    }

    /// <summary>
    /// 根据活动状态，动态显示前台的操作
    /// </summary>
    /// <param name="status"></param>
    /// <returns></returns>
    protected bool GetOperate(string status)
    {
        var mm = UserController.GetUserSession().user_type;
        if (!string.IsNullOrEmpty(status))
        {
            if (Convert.ToInt32(status.Trim()) == (int)PubFun.CAM_STATUS.市场部审批未通过
                  || Convert.ToInt32(status.Trim()) == (int)PubFun.CAM_STATUS.市场部审批通过)
            {
                return false;
            }
            else
            {
                if (UserController.GetUserSession().user_type == "")
                {
                    return false;
                }
                if (PubFun.publicRole.IndexOf(UserController.GetUserSession().Suser_type_id.ToString()) != -1 ||
                     PubFun.regionRole.IndexOf(UserController.GetUserSession().Suser_type_id.ToString()) != -1 ||
                     PubFun.marketRole.IndexOf(UserController.GetUserSession().Suser_type_id.ToString()) != -1)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }

        }
        return true;
    }

    protected string GetStatus(string status)
    {
        return Enum.GetName(typeof(PubFun.CAM_STATUS), Convert.ToInt32(status));
    }

    protected string Delete
    {
        get
        {
            if (tag)
            {
                return "return confirm('您确定要删除吗?');";
            }
            return "return false;";
        }
    }

    protected string getDelete(string tag)
    {
        if (tag == "0")
        {
            return "return confirm('您确定要删除吗?');";
        }
        return "return false;";
    }
    protected string getOperJS(string tag, string type, string cam_uid)
    {

        if (type == "Strat")
        {
            if (tag == "0")
            {
                //判断当前活动是否已经建立对应的渠道
                if (new emp.BLL.Campaign().ifHaveCac(int.Parse(cam_uid)))
                {
                    return "return confirm('您确定要开始活动吗?');";
                }
                else
                {
                    return "alert('请先建立活动对应的渠道！');return false";
                }
            }
            else if (tag == "1")
            {
                return "alert('活动已经开始！');return false";
            }
            else
            {
                return "alert('活动已经结束！');return false";
            }
        }
        else if (type == "End")
        {
            if (tag == "0")
            {
                return "alert('活动尚未开始！');return false";
            }
            else if (tag == "1")
            {
                return "return confirm('您确定要结束活动吗？');";
            }
            else
            {
                return "alert('活动已经结束！');return false";
            }
        }
        else if (type == "Del")
        {
            if (tag == "0")
            {
                return "return confirm('您确定要删除此活动吗？');";
            }
            else if (tag == "1")
            {
                return "alert('活动已经开始，删除请与系统管理员联系');return false;";
            }
            else
            {
                return "alert('活动已经结束，删除请与系统管理员联系');return false";
            }
        }
        else if (type == "Mod")
        {
            if (tag == "0")
            {
                return "return ture;";
            }
            else if (tag == "1")
            {
                return "alert('活动已经开始，修改请与系统管理员联系');return false;";//return false
            }
            else if (tag == "2")
            {
                return "alert('活动已经结束，修改请与系统管理员联系');return false";
            }
        }
        return "";
    }

    protected void campaignList_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}